<include file="Public/header" title="{$siteSetting['site_seo_title']}" keywords="{$siteSetting['site_seo_keywords']}" description="{$siteSetting['site_seo_description']}" />

	<!-- bootstrap-star-rating
	<link rel="stylesheet" href="__TMPL__Public/assets/plugins/bootstrap-star-rating/css/star-rating.min.css" />
	<script src="__TMPL__Public/assets/plugins/bootstrap-star-rating/js/star-rating.min.js"></script> -->
	
	<!-- MAIN -->
    <main class="x-content x-m-b-50">
    	<div class="page-hd">
	        <h1 class="page-hd-title">
				{$item.card_name}
	        </h1>
	        <p class="page-hd-desc">表单预览来自xui</p>
	    </div>
		<section class="x-box with-border pre-form">			
			<div class="x-box-header post-header with-border">
				<div><span class="">付款金额</span><span class="x-pull-right pre-pay-price">¥{$item.card_order_price}</span></div>
			</div>
			<div class="x-box-body">
				<ul class="x-row x-list-value">
					<li class="x-col-12-12">
						<div class="x-row">
							<label class="x-col-2-12">次数</label>
							<span class="x-col-10-12">{$item.card_times}</span>
						</div>
					</li>
				</ul>
			</div>
			<div class="x-box-footer with-border">
				<a class="x-block x-p-15 text-center" href="javascript:" onclick="callpay();" style="color:#0bb20c;">立即支付</a>
			</div>
		</section>
    </main>
    <!-- /MAIN -->
    
	<!-- FOOTER
    <footer class="x-footer">
		<ul class="x-row x-footer-bar with-border-top">
			<li class="x-col-12-12">
				<button class="button button-block button-caution button-large" onclick="callpay();">立即支付</button>
			</li>
		</ul>
	</footer> -->
	<!-- /FOOTER -->

<script type="text/javascript">
// 调用微信JS api 支付
function jsApiCall() {
	WeixinJSBridge.invoke(
		'getBrandWCPayRequest',
		<?php echo $jsApiParameters; ?>,
		function(res) {
			WeixinJSBridge.log(res.err_msg);
			// alert(res.err_code+res.err_desc+res.err_msg);
			var type = '';
			var msg = '';
			var url = '';
			if (res.err_msg == 'get_brand_wcpay_request:ok') {
				type = 'success';
				msg = '支付成功!';
				url = "{:U('Wechat/Index/index')}";
			} else if (res.err_msg == 'get_brand_wcpay_request:cancel') {
				type = 'warning';
				msg = '已取消支付!';
				//url = "{:U('Wechat/Index/index')}";
			} else if (res.err_msg == 'get_brand_wcpay_request:fail') {
				type = 'error';
				msg = '支付失败!';
				//url = "{:U('Wechat/Index/index')}";
			};
			
			xpop.toast({
			    type: type,
		        msg: msg,
		        delay: 1000,
		        afterClose: function() {
		        	if (url) {
		        		window.location.href = url;
		        	}
		        }
		    });
		}
	);
}

function callpay() {
	if (typeof WeixinJSBridge == "undefined") {
	    if (document.addEventListener) {
	        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
	    } else if (document.attachEvent) {
	        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
	        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
	    }
	} else {
	    jsApiCall();
	}
}
</script>
